package cn.webrx;

import java.util.ArrayList;
import java.util.List;

public class List2 {
    public static void main(String[] args) {
        //集合的CRUD操作
        //ListDemo list = new ArrayList(); 不推荐使用

        //使用的泛型，泛型不支持基本类型
        List<String> list = new ArrayList<>();
        //var list2 = new ArrayList<Integer>();

        //添加元素
        list.add("java");
        list.add(0, "html");
        list.add("mysql");
        list.add("vue");
        System.out.println(list);//[html,java,mysql,vue]
        list.addAll(0, List.of("css", "html5", "javascript"));
        System.out.println(list);//[css, html5, javascript, html, java, mysql, vue]
        list.addAll(List.of("11", "22", "33"));
        System.out.println(list);//[css, html5, javascript, html, java, mysql, vue, 11, 22, 33]
        list.addAll(list.indexOf("java"), List.of("java8", "java9", "java10"));
        System.out.println(list);
        list.add("java");
        list.add(0, "java");

        //删除元素
        System.out.println(list);
        //list.remove("java");

        //list.removeAll(ListDemo.of("java"));

        //删除所有包含有java的字符串

        list.removeIf(a -> a.contains("java"));

        //删除指定索引下标位置
        list.remove(0);
        //删除所有元素
        list.clear();
        //list.removeIf(e->true);
        System.out.println(list);

        List<Integer> nn = new ArrayList<>(List.of(1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4,2));
        System.out.println(nn.size());
        System.out.println(nn);

        //nn.remove(3); 删除的索引3 元素4

        //nn.remove((Integer) 3);
        nn.removeAll(List.of(3));

        System.out.println(nn);


        //查询判断元素
        System.out.println(list.isEmpty());
        System.out.println(nn.contains(2));
        System.out.println(nn.indexOf(2));//1
        System.out.println(nn.lastIndexOf(2));//9
        System.out.println(nn.lastIndexOf(22));//-1
        System.out.println(nn.containsAll(List.of(4,2,20)));


        //遍历集合


        //数组和List相互转换

    }
}
